package com.qezhhnjy.mall.member.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.member.IntegrationChangeHistory;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.member.service.IntegrationChangeHistoryService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 积分变化历史记录 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "积分变化历史记录接口")
@Slf4j
@RequestMapping("/integration-change-history")
public class IntegrationChangeHistoryController {
    @Resource
    private IntegrationChangeHistoryService integrationChangeHistoryService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取积分变化历史记录信息")
    public BaseResult<IntegrationChangeHistory> get(Long id) {
        IntegrationChangeHistory integrationChangeHistory = integrationChangeHistoryService.getById(id);
        return BaseResult.success(integrationChangeHistory);
    }

    @PostMapping("/save")
    @Operation(summary = "新增积分变化历史记录信息")
    public BaseResult<IntegrationChangeHistory> save(@RequestBody IntegrationChangeHistory integrationChangeHistory) {
        integrationChangeHistoryService.save(integrationChangeHistory);
        return BaseResult.success(integrationChangeHistory);
    }

    @PutMapping("/update")
    @Operation(summary = "更新积分变化历史记录信息")
    public BaseResult<IntegrationChangeHistory> update(@RequestBody IntegrationChangeHistory integrationChangeHistory) {
        integrationChangeHistoryService.updateById(integrationChangeHistory);
        return BaseResult.success(integrationChangeHistory);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取积分变化历史记录信息")
    public BaseResult<Page<IntegrationChangeHistory>> page(@RequestBody Page<IntegrationChangeHistory> page) {
        integrationChangeHistoryService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除积分变化历史记录信息")
    public BaseResult<Long> delete(Long id) {
        integrationChangeHistoryService.removeById(id);
        return BaseResult.success(id);
    }
}

